package com.jc.demo.hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;

import java.io.IOException;

public class CreateTableDemo {

    public static void main(String[] args) throws IOException {
        Configuration config = HBaseConfiguration.create();
        config.addResource("hbase-site.xml");
        config.addResource("core-site.xml");
        try (Connection connection = ConnectionFactory.createConnection(config);
             Admin admin = connection.getAdmin()) {


            //creating table descriptor
            ColumnFamilyDescriptor personal = ColumnFamilyDescriptorBuilder.newBuilder("personal".getBytes()).build();
            ColumnFamilyDescriptor professional = ColumnFamilyDescriptorBuilder.newBuilder("professional".getBytes()).build();
            TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(TableName.valueOf("emp")).setReadOnly(false)//
                     .setColumnFamily(personal)//
                     .setColumnFamily(professional)//
                     .build();


            admin.createTable(tableDescriptor);
            System.out.println("emp create success");
        }
    }
}
